home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / misc / RISCOS / gnuplot_ar < prev    next >
Text File  |  1995-11-22  |  53KB  |  2,007 lines

  1. // Acorn RISC OS RLaB version of GNUPlot interface 'r' files 
  2.  
  3. //-------------------------------------------------------------------//
  4.  
  5. //  Syntax:    plot ( A, KeyTitles, I ) or plot ( X, Y, I )
  6. //        replot ( A, KeyTitles, I ) or replot ( X, Y, I ) or replot ( I )
  7. //        splot ( X, Y, Z, KeyTitles, I )
  8. //        cont ( X, Y, Z, KeyTitles, I )
  9. //        pstring ( "string", I )
  10. //        postplot ( "file_name", "mode", I )
  11. //        latexplot ( "file_name", "mode", I )
  12. //        printplot ( "printer-name", I )
  13. //        psave ( "file_name", A )
  14. //        pssave ( "file_name", X, Y, Z )
  15. //        multiplot ( rows, columns, I )    !!!!!! Special GNUPLOT-contrib needed !!!!!!
  16. //        nomultiplot ( I )        !!!!!! Special GNUPLOT-contrib needed !!!!!!
  17. //        plotyy ( I )            !!!!!! Special GNUPLOT-contrib needed !!!!!!
  18. //        noplotyy ( I )            !!!!!! Special GNUPLOT-contrib needed !!!!!!
  19. //        pclose ( I )
  20. //        setterm ( "term", I )
  21. //        showplot ( I )
  22. //        showpwin ( )
  23. //        phelp ( "string", I)
  24. //        autoscale ( "axis", I )
  25. //        range ( x-start, x-end, y-start, y-end, z-start, z-end, I )
  26. //        xrange ( start, end, I )
  27. //        yrange ( start, end, I )
  28. //        zrange ( start, end, I )
  29. //        xtics ( start, end, incr, I ) or xtics (vector, I ) or xtics ( I )
  30. //        noxtics ( I )
  31. //        ytics ( start, end, incr, I ) or ytics (vector, I ) or ytics ( I )
  32. //        noytics ( I )
  33. //        ztics ( start, end, incr, I ) or ytics (vector, I ) or ytics ( I )
  34. //        noztics ( I )
  35. //        loglog ( I )
  36. //        semilogx ( I )
  37. //        semilogy ( I )
  38. //        nolog ( I )
  39. //        xlabel ( "label_name", I )
  40. //        ylabel ( "label_name", I )
  41. //        zlabel ( "label_name", I )
  42. //        title ( "title_name", I )
  43. //        notitle ( "title_name", I )
  44. //        linestyle ( "line_style", I )
  45. //        pformat ( "format-string", "axis", I )
  46. //        key ( x, y, z, I )    (*)
  47. //        nokey ( I )
  48. //        grid ( I )
  49. //        nogrid ( I )
  50. //        axis ( I )
  51. //        noaxis ( I )
  52. //        label ( "label_text", x, y, z, labelnr, I )    (*)
  53. //        nolabel ( labelnr, I )
  54. //        time ( I )
  55. //        notime ( I )
  56.  
  57. //        (*) Be alert how you send these commands. You will get into trouble
  58. //            if you try to send "I" without fully specified coordinates.
  59. //            Do not leave out "z" or "labelnr" for example.
  60.  
  61. // Description:
  62.  
  63. //  The plot function plots numeric data via the GNUPLOT program. The
  64. //  argument A can be a matrix, or a list of matrices, or a string.
  65. //  plot can also plot a vector Y versus a vector X. X and Y can
  66. //  also be matrixes. 
  67. //  When A is a matrix, columns 2 through N are plotted versus the 1st
  68. //  column. When A is a list of matrices, each matrix is plotted
  69. //  versus it's own 1st column. When A is a string, the string is sent
  70. //  to GNUPLOT as a command.
  71.  
  72. //  plot ( M )                  plots the contents of matrix M
  73. //  plot( X, Y )            plots Y verus X
  74. //  plot ( << M1 ; M2>> )        plots M1, and M2 on the same graph
  75. //  plot ( "set noborder" )        sends the string directly to
  76. //                      GNUPLOT as a command
  77.  
  78. //  Using a list of matrices as an argument to plot is useful when the
  79. //  the independent variable (1st column) of each matrix is different.
  80.  
  81. //  The second and third, and optional argument to plot denotes the plot process
  82. //  number and sends key-titles. The plot() function will open distinct plot
  83. //  processes when given distinct values of N. When this feature is used in a
  84. //  X-windows environment, the effect is to create separate plot windows.
  85. //  The KeyTitles is a string-vector containing the titles to be plotted as keys.
  86. //  They are chosen from the beginning of KeyTitles[1] and so on.
  87. //  For example:
  88.  
  89. //  plot ( M );                plot the contents if matrix M
  90. //  plot ( 2.*M, 1 );            plot 2 times M, to another window
  91. //  plot (<<M1;M2>>, KeyTitles, 2);    plot M1, and M2 on the same graph in another
  92. //                    window with the keytitles from KeyTitles
  93.  
  94. //  The replot() command can be used to replot the last plot. It can also be
  95. //  used to superinpose a new plot in an old plot.
  96.  
  97. //  replot( I );            replot the I-th plot-window
  98. //  replot( A, KeyTitles, I );        superinpose new plot on the I-th plot-window
  99. //  replot( X, Y, I );            superinpose new plot on the I-th plot-window
  100.  
  101. //  For 3D-plotting there are several commands. splot() makes a 3D-surface plot
  102. //  and cont() makes a 2D-contour plot. This is in GNUPLOT a 3D-plot with no 
  103. //  surface.
  104. //  
  105. //  The splot() function splots numeric data via the GNUPLOT program. The
  106. //  argument Z is a matrix as functions of vectors X and Y.
  107.  
  108. //  splot ( X, Y, Z )            splots the contents of matrix Z
  109. //                    versus X and Y
  110. //  splot ( Z )                splots the contents of matrix Z
  111. //                    versus rows and columns
  112. //  splot ( X, Y, [Z1,Z2] )        splots Z1, and Z2 on the same graph
  113. //  cont ( X, Y, Z )            splots the contents of matrix Z
  114. //                    as a 2D-contour-plot
  115. //  cont ( X, Y, [Z1,Z2] )        splots Z1, and Z2 on the same graph
  116. //                    as a 2D-contour-plot
  117.  
  118. //  The psave() and pssave() saves the usual temporary file to a specific, 
  119. //  non-temporary file named "file_name". psave() is for 2D-plots and pssave() 
  120. //  is for 3D-plots. This is useful if you wish to save session-output in a 
  121. //  GNUPLOT-way.
  122.  
  123. //  multiplot() allows you to make multiple plots in one window. After giving 
  124. //  the command you enter multimode. After making rows*columns plot commands 
  125. //  you automaticly leaves this mode. plotyy() allows you to make one plot with 
  126. //  two y-axes. You will enter multimode, and after making two plot commands you 
  127. //  leave. The first plot will be on the left axis and the second on the right. 
  128. //  If you want to leave multiplot() or plotyy() before ending the plot commands
  129. //  just type nomultiplot() or noplotyy().
  130. //  If you want a PostScript output from plots made in multimode you do not 
  131. //  use postplot(). This will not work. plotyy() is for 2D-plots only. 
  132. //  GNUPLOT-3.5 DO NOT SUPPORT THESE FEATURES. If you want to use them 
  133. //  you must add GNUPLOT-contributions and recompile GNUPLOT.
  134.  
  135. //  The pclose function closes (destroys)  the I-th GNUPLOT
  136. //  subprocess. If I = "all", all GNUPLOT subprocess are closed.
  137.  
  138. //  The postplot() function generates a PostScript file named "file_name" 
  139. //  of the current I-th plot. "mode" is further postscript definitions to 
  140. //  GNUPLOT if needed, for example "eps color 'Times-Roman' 14" for making
  141. //  a smaller plot in color with Times-Roman-font size 14.
  142. //  The PostScript plot is saved in a file for printing, or whatever. 
  143. //  Immediately after calling postplot(), the GNUPLOT variables
  144. //  term, and output are reset to there former values.
  145. //  printplot() generates a PostScript file and sends it to the printer.
  146. //  latexplot() generates a LaTeX file named "file_name" of the current 
  147. //  I-th plot. 
  148.  
  149. //  The setterm function allows the user to set/reset the I-th plot's
  150. //  term type. The argument "term" is a string that corresponds to one
  151. //  of GNUPLOT's available term types, for example "vttek".
  152.  
  153. //  The showplot function prints the contents of the I-th plot list to
  154. //  stdout.
  155. //  The showpwin function prints the currently existing plotwindows 
  156. //  to stdout.
  157.  
  158. //  A bunch of often used commands to GNUPLOT has special functions.
  159. //  These could just as well be sent as strings, but this makes life easier.
  160. //  These are range(), xrange(), yrange(), zrange(), xtics(), ytics(), 
  161. //  noxtics(), noytics(), loglog(), semilogx(), semilogy(), nolog(), 
  162. //  autoscale(), xlabel(), ylabel(), zlabel(), 
  163. //  title(), notitle(), linestyle(), pformat(), key(), nokey(), 
  164. //  grid(), nogrid(), axis(), noaxis(), label(), nolabel(), 
  165. //  time() and notime().
  166.  
  167. //  The xtics(), ytics() and ztics() functions sets the tics on the axes. 
  168. //  If it is used as xtics(start,end,incr,I), the tics will be set 
  169. //  for plotwindow I, starting from "start", ending at "end", 
  170. //  with an increment of "incr". 
  171. //  If, however, it is used as xtics([a,b,c,d],I), the tics will 
  172. //  set at "a", "b", "c" and "d" in plotwindow I. 
  173. //  The command xtics(I) will reset the tics in plotwindow I.
  174. //  The noxtics() function results in a tics-less x-axis.
  175.  
  176. //  The plot function is an interface to the GNUPLOT program. The plot
  177. //  function uses temporary files and Rlab's piping capability to
  178. //  transparently plot numerical data via GNUPLOT. Since the plot
  179. //  function is an rfile, it could easily be modified to to use
  180. //  another plotting program.
  181.  
  182. //  To be able to use all commands in this r-file you must add some
  183. //  contributions to GNUPLOT and recompile it. These are "multiplot"
  184. //  and "borders". See the GNUPLOT FAQ for help.
  185.  
  186. //-------------------------------------------------------------------//
  187.  
  188.  
  189.  
  190. _RePlotParameter = zeros(1,100);
  191.  
  192. //
  193. // List to contain plot-object lists.
  194. //
  195.  
  196. static (p);
  197. p = <<>>;
  198.  
  199. //
  200. // Internal plot-related functions
  201. //
  202.  
  203. static (plotl, plotm, splotm, plots);
  204. static (pobj_Create, pobj_Reset, pobj_Destroy);
  205. static (pobj_TmpFileName, pobj_WriteData, pobj_PlotCmd, pobj_RePlotCmd, pobj_SPlotCmd);
  206. static (pobj_PlotKeyTitle, pobj_Plot, pobj_SetRm, pobj_Rm);
  207.  
  208.  
  209.  
  210. //
  211. // User interface to plot functionality
  212. //
  213.  
  214. plot = function ( data, titles, N )
  215. {
  216.     local( WaitAMoment, sizemem, flag1, flag2, flag3 )
  217.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  218.  
  219.     flag1 = 0;
  220.     flag2 = 0;
  221.     flag3 = 0;
  222.     // Check the existence titles
  223.     if (exist (titles)) {
  224.     if (class (titles) == "num") {
  225.         if (max (size (titles)) == 1) {
  226.         N = titles;
  227.         else
  228.         flag1=1;
  229.         sizemem = size (data);
  230.         if (data.nr < data.nc) {
  231.             flag2 = 1;
  232.             data = data';
  233.         }
  234.         if (titles.nr < titles.nc) {
  235.             flag3 = 1;
  236.             titles = titles';
  237.         }
  238.         data = [data,titles];
  239.         }
  240.     }
  241.     }
  242.     
  243.     // Set the default plot-object
  244.     if (!exist (N)) { N = 0; }
  245.  
  246.     // Check the existence of p.[N]
  247.     if (max (size (N)) != 1) { error ("plot(): N must be a 1-by-1"); }
  248.     if (exist (p.[N])) {
  249.     pobj_Reset (N);
  250.     else
  251.     pobj_Create (N);
  252.     }
  253.  
  254.     // Check for multiplot and/or plotyy mode
  255.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  256.     // Delay (RLaB is a bit to fast)
  257.     for(i in 1:1000) {
  258.         WaitAMoment=1;
  259.         clear(WaitAMoment);
  260.     }
  261.     // Check for plotyy mode
  262.     if (exist (_PlotYyParameter)) {
  263.         if (_PlotYyParameter==1) {
  264.         printf (" Plot on left y-axis done!\n");
  265.         if (!exist (_MultiPlotParameter)) {
  266.             system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  267.         }
  268.         system("taskwindow \"gnupipe set border 7\" -wimpslot 32k -quit");
  269.         else if (_PlotYyParameter==2) {
  270.             printf (" Plot on right y-axis done!\n");
  271.             system("taskwindow \"gnupipe set border 8\" -wimpslot 32k -quit");
  272.         }   }
  273.         _PlotYyParameter=_PlotYyParameter+1;
  274.     }
  275.     // Check for multiplot mode
  276.     if (exist (_MultiPlotParameter)) {
  277.         printf (" Plot number %i/%i done!\n",_MultiPlotParameter[3],_MultiPlotParameter[1]*_MultiPlotParameter[2]);
  278.         if (_MultiPlotParameter[3]==1) {
  279.         system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  280.         system("taskwindow \"gnupipe set size " + 1./_MultiPlotParameter[2] + "," + 1./_MultiPlotParameter[1] + "\" -wimpslot 32k -quit");
  281.         }
  282.         N=_MultiPlotParameter[4];
  283.         system ("taskwindow \"gnupipe set orgin " +_MultiOrginParameter[_MultiPlotParameter[3];1] + "," + _MultiOrginParameter[_MultiPlotParameter[3];2] + "\" -wimpslot 32k -quit");
  284.         if (exist (_PlotYyParameter)) {
  285.         if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  286.         else
  287.         _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  288.         }
  289.     }
  290.     }
  291.    
  292.  
  293.     // Time to plot
  294.     if (class (data) == "num") {
  295.         system("taskwindow \"gnupipe set noparametric\" -wimpslot 32k -quit");
  296.     pobj_Rm (N);
  297.     plotm (data, N, 1, titles);
  298.     pobj_Plot (N);
  299.     pobj_SetRm (N);
  300.     else if (class (data) == "string") {
  301.         plots (data, N);
  302.         pobj_Plot (N);
  303.         else if (class (data) == "list") {
  304.         pobj_Rm (N);
  305.         plotl (data, N, titles);
  306.         pobj_Plot (N);
  307.         pobj_SetRm (N);    
  308.         else
  309.         error ("Invalid data for plot()");
  310.     }   }   }
  311.     
  312.     // Check for multiplot and/or plotyy mode
  313.     // Check for plotyy mode
  314.     if (exist (_PlotYyParameter)) {
  315.     if (_PlotYyParameter==3) {
  316.         if (!exist (_MultiPlotParameter)) { 
  317.           system("taskwindow \"gnupipe setnomultiplot\" -wimpslot 32k -quit"); 
  318.         }
  319.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  320.         clear(_PlotYyParameter);
  321.     }
  322.     }
  323.     // Check for multiplot mode
  324.     if (exist (_MultiPlotParameter)) {
  325.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  326.         system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  327.         system ("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  328.         system ("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  329.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  330.         clear(_MultiPlotParameter);
  331.         clear(_MultiOrginParameter);
  332.     }
  333.     }
  334.     
  335.     if (flag1 == 1) { 
  336.     if (flag2 == 0) {
  337.         data = data[;1:sizemem[2]];
  338.         else
  339.         data = data[;1:sizemem[1]];
  340.     }
  341.     if (flag2 == 1) { data = data'; }
  342.     if (flag3 == 1) { titles = titles'; }
  343.     }
  344.  
  345. };
  346.  
  347. //
  348. // User interface to replot functionality
  349. //
  350.  
  351. replot = function ( data, titles, N )
  352. {
  353.     local( sizemem, flag1, flag2, flag3, flag4 );
  354.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  355.     global( _RePlotParameter );
  356.     
  357.     flag1 = 0;
  358.     flag2 = 0;
  359.     flag3 = 0;
  360.     flag4 = 0;
  361.     // Check the existence titles
  362.     if (exist (titles)) {
  363.     if (class (titles) == "num") {
  364.         if (max (size (titles)) == 1) {
  365.         N = titles;
  366.         else
  367.         flag1=1;
  368.         sizemem = size (data);
  369.         if (data.nr < data.nc) {
  370.             flag2 = 1;
  371.             data = data';
  372.         }
  373.         if (titles.nr < titles.nc) {
  374.             flag3 = 1;
  375.             titles = titles';
  376.         }
  377.         data = [data,titles];
  378.         }
  379.     }
  380.     }
  381.     
  382.     if (exist (data) && !exist (titles)) {
  383.     if (max(size(data)) == 1) {
  384.         N = data;
  385.         clear(data);
  386.         flag4=1;
  387.     }
  388.     }
  389.     // Set the default plot-object
  390.     if (!exist (N)) { N = 0; }
  391.  
  392.     // Check the existence of p.[N]
  393.     if (max (size (N)) != 1) { error ("plot(): N must be a 1-by-1"); }
  394.     if (exist (p.[N])) {
  395.     pobj_Reset (N);
  396.     else
  397.     pobj_Create (N);
  398.     }
  399.  
  400.     // Time to plot
  401.     if (!exist(data)) {
  402.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit");
  403.     if (flag4 == 1) { data = N; }
  404.     return 0;
  405.     }
  406.     if (class (data) == "num") {
  407.     system ("taskwindow \"gnupipe set noparametric\" -wimpslot 32k -quit");
  408.     _RePlotParameter[N+1] = _RePlotParameter[N+1]+1;
  409.     pobj_Rm (N);
  410.     replotm (data, N, 1, titles);
  411.     pobj_Plot (N);
  412.     pobj_SetRm (N);
  413.     else if (class (data) == "string") {
  414.         plots (data, N);
  415.         pobj_Plot (N);
  416.         else if (class (data) == "list") {
  417.         pobj_Rm (N);
  418.         plotl (data, N, titles);
  419.         pobj_Plot (N);
  420.         pobj_SetRm (N);    
  421.         else
  422.         error ("Invalid data for replot()");
  423.     }   }   }
  424.  
  425.     if (flag1 == 1) { 
  426.     if (flag2 == 0) {
  427.         data = data[;1:sizemem[2]];
  428.         else
  429.         data = data[;1:sizemem[1]];
  430.     }
  431.     if (flag2 == 1) { data = data'; }
  432.     if (flag3 == 1) { titles = titles'; }
  433.     }
  434.  
  435. };
  436.  
  437.  
  438. //
  439. // User interface to splot functionality
  440. //
  441.  
  442. splot = function ( datax, datay, datazz, titles, N )
  443. {
  444.     local (flag1, flag2, flag3, flag4, flagx, flagy, WaitAMoment)
  445.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  446.  
  447.     // Reset flags
  448.     flag1=0;
  449.     flag2=0;
  450.     flag3=0;
  451.     flag4=0;
  452.     flagx=0;
  453.     flagy=0;
  454.  
  455.     // Check what has been sent here
  456.     // One input!
  457.     if (!exist (datay)) {
  458.     datazz=datax;
  459.     datax=1:datazz.nc;
  460.     datax=datax';
  461.     datay=1:datazz.nr;
  462.     datay=datay';
  463.     flag1=flag1+1;
  464.     // Two inputs!
  465.     else if (!exist (datazz)) {
  466.         if (exist (datay)) {
  467.         if (class (datay) == "num") {
  468.             N = datay;
  469.             flag2=flag2+0;
  470.             else
  471.             titles = datay;
  472.             flag2=flag2+1;
  473.         }
  474.         }
  475.         datazz=datax;
  476.         datax=1:datazz.nc;
  477.         datax=datax';
  478.         datay=1:datazz.nr;
  479.         datay=datay';
  480.         flag2=flag2+1;
  481.         // Three inputs!
  482.         else if (!exist (titles)) {
  483.         if (class (datay) != "num") {
  484.             titles = datay;
  485.             N = datazz;
  486.             datazz=datax;
  487.             datax=1:datazz.nc;
  488.             datax=datax';
  489.             datay=1:datazz.nr;
  490.             datay=datay';
  491.             flag3=flag3+1;
  492.         }
  493.         // Four inputs!
  494.         else if (!exist (N)) {
  495.             if (class (titles) == "num") {
  496.             N=titles;
  497.             flag4=flag4+1;
  498.             }
  499.     }   }   }   }
  500.     
  501.     // Transpose x- and y-vectors if nessecary
  502.     if (datax.nc != 1 ) {
  503.     if (datax.nr != 1 ) {
  504.         error ("Invalid data for x-axis (not a vector)");
  505.         else
  506.         datax = datax';
  507.         flagx=flagx+1;
  508.     }
  509.     }
  510.     if (datay.nc != 1 ) {
  511.     if (datay.nr != 1 ) {
  512.         error ("Invalid data for y-axis (not a vector)");
  513.         else
  514.         datay = datay';
  515.         flagy=flagy+1;
  516.     }
  517.     }
  518.     
  519.     // Check how many splots to do
  520.     plotantal=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  521.     if (plotantal == int(plotantal)) {
  522.     
  523.     // Set the default splot-object
  524.     if (!exist (N)) { N = 0; }
  525.  
  526.     // Check the existence of p.[N]
  527.     if (max (size (N)) != 1) { error ("splot(): N must be a 1-by-1"); }
  528.     if (exist (p.[N])) {
  529.         pobj_Reset (N);
  530.         else
  531.         pobj_Create (N);
  532.     }
  533.  
  534.     // Check for multiplot and/or plotyy mode
  535.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  536.         // Delay (RLaB is a bit to fast)
  537.         for(i in 1:1000) {
  538.         WaitAMoment=1;
  539.         clear(WaitAMoment);
  540.         }
  541.         // Check for plotyy mode
  542.         if (exist (_PlotYyParameter)) {
  543.         if (_PlotYyParameter==1) {
  544.             if (!exist (_MultiPlotParameter)) {
  545.             system ("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  546.             }
  547.             system ("taskwindow \"gnupipe set border 7\" -wimpslot 32k -quit");
  548.             else if (_PlotYyParameter==2) {
  549.             system ("taskwindow \"gnupipe set border 8\" -wimpslot 32k -quit");
  550.         }   }
  551.         _PlotYyParameter=_PlotYyParameter+1;
  552.         }
  553.         // Check for multiplot mode
  554.         if (exist (_MultiPlotParameter)) {
  555.         printf (" Plot number %i/%i done!\n",_MultiPlotParameter[3],_MultiPlotParameter[1]*_MultiPlotParameter[2]);            
  556.         if (_MultiPlotParameter[3]==1) {
  557.             system ("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  558.             system ("taskwindow \"gnupipe set size " + 1./_MultiPlotParameter[2], + "," + 1./_MultiPlotParameter[1]+ "\" -wimpslot 32k -quit");
  559.         }
  560.         N=_MultiPlotParameter[4];
  561.         system ("taskwindow \"set orgin " + _MultiOrginParameter[_MultiPlotParameter[3];1] + "," +_MultiOrginParameter[_MultiPlotParameter[3];2] + "\" -wimpslot 32k -quit");
  562.         if (exist (_PlotYyParameter)) {
  563.             if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  564.             else
  565.             _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  566.         }
  567.         }
  568.     }
  569.  
  570.     if (class (datax) != "num") {
  571.         error ("Invalid data class for splot() in x-vector (must be num)");
  572.         else if (class (datay) != "num") {
  573.         error ("Invalid data class for splot() in y-vector (must be num)");
  574.         else if (class (datazz) != "num") {
  575.             error ("Invalid data class for splot() in x-matrix (must be num)");
  576.             else
  577.             system ("taskwindow \"gnupipe set parametric\" -wimpslot 32k -quit");
  578.             system ("taskwindow \"gnupipe set view 60, 30, 1, 1\" -wimpslot 32k -quit");
  579.             system ("taskwindow \"gnupipe set surface\" -wimpslot 32k -quit");
  580.             system ("taskwindow \"gnupipe set nocontour\" -wimpslot 32k -quit");
  581.             pobj_Rm (N);
  582.             splotm (datax, datay, datazz, N, 1, titles);
  583.             pobj_Plot (N);
  584.             pobj_SetRm (N);
  585.     }   }   }
  586.     else
  587.     error ("Invalid data for splot(), bad x/y-range in z-matrix");
  588.     }
  589.     
  590.     // Restore the output/input
  591.     if (flag1 == 1) { datax=datazz; }
  592.     if (flag2 == 1) {
  593.     datax=datazz;
  594.     datay=N;
  595.     else if (flag2 == 2) {
  596.         datax=datazz;
  597.         datay=titles;
  598.     }   }
  599.     if (flag3 == 1) {
  600.     datax=datazz;
  601.     datay=titles;
  602.     datazz=N;
  603.     }
  604.     if (flag4 == 1) { titles=N; }
  605.     if (flagx == 1) { datax=datax'; }
  606.     if (flagy == 1) { datay=datay'; }
  607.  
  608.     // Check for multiplot and/or plotyy mode
  609.     // Check for plotyy mode
  610.     if (exist (_PlotYyParameter)) {
  611.     if (_PlotYyParameter==3) {
  612.         if (!exist (_MultiPlotParameter)) { 
  613.           system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit"); 
  614.         }
  615.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  616.         clear(_PlotYyParameter);
  617.     }
  618.     }
  619.     // Check for multiplot mode
  620.     if (exist (_MultiPlotParameter)) {
  621.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  622.         system("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  623.         system("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  624.         system("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  625.         system("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  626.         clear(_MultiPlotParameter);
  627.         clear(_MultiOrginParameter);
  628.     }
  629.     }
  630. };
  631.  
  632.  
  633.  
  634. //
  635. // User interface to splot functionality as 2D-contour
  636. //
  637.  
  638. cont = function ( datax, datay, datazz, titles, N )
  639. {
  640.     local (flag1, flag2, flag3, flag4, flagx, flagy, WaitAMoment)
  641.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  642.  
  643.     // Reset flags
  644.     flag1=0;
  645.     flag2=0;
  646.     flag3=0;
  647.     flag4=0;
  648.     flagx=0;
  649.     flagy=0;
  650.  
  651.     // Check what has been sent here
  652.     // One input!
  653.     if (!exist (datay)) {
  654.     datazz=datax;
  655.     datax=1:datazz.nc;
  656.     datax=datax';
  657.     datay=1:datazz.nr;
  658.     datay=datay';
  659.     flag1=flag1+1;
  660.     // Two inputs!
  661.     else if (!exist (datazz)) {
  662.         if (exist (datay)) {
  663.         if (class (datay) == "num") {
  664.             N = datay;
  665.             flag2=flag2+0;
  666.             else
  667.             titles = datay;
  668.             flag2=flag2+1;
  669.         }
  670.         }
  671.         datazz=datax;
  672.         datax=1:datazz.nc;
  673.         datax=datax';
  674.         datay=1:datazz.nr;
  675.         datay=datay';
  676.         flag2=flag2+1;
  677.         // Three inputs!
  678.         else if (!exist (titles)) {
  679.         if (class (datay) != "num") {
  680.             titles = datay;
  681.             N = datazz;
  682.             datazz=datax;
  683.             datax=1:datazz.nc;
  684.             datax=datax';
  685.             datay=1:datazz.nr;
  686.             datay=datay';
  687.             flag3=flag3+1;
  688.         }
  689.         // Four inputs!
  690.         else if (!exist (N)) {
  691.             if (class (titles) == "num") {
  692.             N=titles;
  693.             flag4=flag4+1;
  694.             }
  695.     }   }   }   }
  696.     
  697.     // Transpose x- and y-vectors if nessecary
  698.     if (datax.nc != 1 ) {
  699.     if (datax.nr != 1 ) {
  700.         error ("Invalid data for x-axis (not a vector)");
  701.         else
  702.         datax = datax';
  703.         flagx=flagx+1;
  704.     }
  705.     }
  706.     if (datay.nc != 1 ) {
  707.     if (datay.nr != 1 ) {
  708.         error ("Invalid data for y-axis (not a vector)");
  709.         else
  710.         datay = datay';
  711.         flagy=flagy+1;
  712.     }
  713.     }
  714.     
  715.     // Check how many splots to do
  716.     plotantal=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  717.     if (plotantal == int(plotantal)) {
  718.  
  719.     // Set the default splot-object
  720.     if (!exist (N)) { N = 0; }
  721.  
  722.     // Check the existence of p.[N]
  723.     if (max (size (N)) != 1) { error ("splot(): N must be a 1-by-1"); }
  724.     if (exist (p.[N])) {
  725.         pobj_Reset (N);
  726.         else
  727.         pobj_Create (N);
  728.     }
  729.  
  730.     // Check for multiplot and/or plotyy mode
  731.     if (exist (_MultiPlotParameter) || exist (_PlotYyParameter)) {
  732.         // Delay (RLaB is a bit to fast)
  733.         for(i in 1:1000) {
  734.         WaitAMoment=1;
  735.         clear(WaitAMoment);
  736.         }
  737.         // Check for plotyy mode
  738.         if (exist (_PlotYyParameter)) {
  739.         if (_PlotYyParameter==1) {
  740.             if (!exist (_MultiPlotParameter)) {
  741.                 system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  742.             }
  743.             system ("taskwindow \"gnupipe set border 7\" -wimpslot 32k -quit");
  744.             else if (_PlotYyParameter==2) {
  745.                 system("taskwindow \"gnupipe set border 8\" -wimpslot 32k -quit");
  746.         }   }
  747.         _PlotYyParameter=_PlotYyParameter+1;
  748.         }
  749.         // Check for multiplot mode
  750.         if (exist (_MultiPlotParameter)) {
  751.         if (_MultiPlotParameter[3]==1) {
  752.             system("taskwindow \"gnupipe set multiplot\" -wimpslot 32k -quit");
  753.             system("taskwindow \"gnupipe set size " + 1/_MultiPlotParameter[2] + "," + 1/_MultiPlotParameter[1] + "\" -wimpslot 32k -quit");
  754.         }
  755.         N=_MultiPlotParameter[4];
  756.             system ("taskwindow \"gnupipe set orgin " +_MultiOrginParameter[_MultiPlotParameter[3];1] + "," + _MultiOrginParameter[_MultiPlotParameter[3];2] + "\" -wimpslot 32k -quit");
  757.         if (exist (_PlotYyParameter)) {
  758.             if (_PlotYyParameter==3) {_MultiPlotParameter[3]=_MultiPlotParameter[3]+1; }
  759.             else
  760.             _MultiPlotParameter[3]=_MultiPlotParameter[3]+1;
  761.         }
  762.         }
  763.     }
  764.  
  765.     if (class (datax) != "num") {
  766.         error ("Invalid data class for splot() in x-vector (must be num)");
  767.         else if (class (datay) != "num") {
  768.         error ("Invalid data class for splot() in y-vector (must be num)");
  769.         else if (class (datazz) != "num") {
  770.             error ("Invalid data class for splot() in x-matrix (must be num)");
  771.             else
  772.             system ("taskwindow \"gnupipe set parametric\" -wimpslot 32k -quit");
  773.             system ("taskwindow \"gnupipe set view 0, 0, 1\" -wimpslot 32k -quit");
  774.             system ("taskwindow \"gnupipe set nosurface\" -wimpslot 32k -quit");
  775.             system ("taskwindow \"gnupipe set contour\" -wimpslot 32k -quit");
  776.             pobj_Rm (N);
  777.             splotm (datax, datay, datazz, N, 1, titles);
  778.             pobj_Plot (N);
  779.             pobj_SetRm (N);
  780.     }   }   }
  781.     else
  782.     error ("Invalid data for splot(), bad x/y-range in z-matrix");
  783.     }
  784.     
  785.     // Restore the output/input
  786.     if (flag1 == 1) { datax=datazz; }
  787.     if (flag2 == 1) {
  788.     datax=datazz;
  789.     datay=N;
  790.     else if (flag2 == 2) {
  791.         datax=datazz;
  792.         datay=titles;
  793.     }   }
  794.     if (flag3 == 1) {
  795.     datax=datazz;
  796.     datay=titles;
  797.     datazz=N;
  798.     }
  799.     if (flag4 == 1) { titles=N; }
  800.     if (flagx == 1) { datax=datax'; }
  801.     if (flagy == 1) { datay=datay'; }
  802.  
  803.     // Check for multiplot and/or plotyy mode
  804.     // Check for plotyy mode
  805.     if (exist (_PlotYyParameter)) {
  806.     if (_PlotYyParameter==3) {
  807.         if (!exist (_MultiPlotParameter)) { 
  808.           system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  809.         }
  810.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  811.         clear(_PlotYyParameter);
  812.     }
  813.     }
  814.     // Check for multiplot mode
  815.     if (exist (_MultiPlotParameter)) {
  816.     if (_MultiPlotParameter[3]==_MultiPlotParameter[1]*_MultiPlotParameter[2]+1) {
  817.         system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  818.         system ("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  819.         system ("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  820.         system ("taskwindow \"gnupipe set border\" -wimpslot 32k -quit");
  821.         clear(_MultiPlotParameter);
  822.         clear(_MultiOrginParameter);
  823.     }
  824.     }
  825. };
  826.  
  827.  
  828.  
  829. //
  830. // Send string to GNUPLOT
  831. //
  832.  
  833. pstring = function ( string, N )
  834. {
  835.     if (!exist (N)) { N = 0; }
  836.     if (!exist (p.[N])) { pobj_Create (N); }
  837.     system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");
  838. };
  839.  
  840.  
  841.  
  842. //
  843. // User interface to save a plot ot splot as postscript hardcopy
  844. //
  845.  
  846. postplot = function ( file, mode, N )
  847. {
  848.     local ( flag1 );
  849.     flag1 = 0;
  850.     if (!exist (N) && exist (mode)) {
  851.     if (class (mode) == "num") {
  852.         N = mode;
  853.         flag1 = 1;
  854.     }
  855.     }
  856.  
  857.     if (!exist (N)) { N = 0; }
  858.     if (!exist (p.[N])) { error ("No existing plot to make hardcopy from"); }
  859.  
  860.     // Make hardcopy file
  861.     if (!exist (mode)) { mode="default"; }
  862.     if (class (mode) == "num") { mode="default"; }
  863.  
  864.     system ("taskwindow \"gnupipe set term post " + mode + "\" -wimpslot 32k -quit");
  865.     system ("taskwindow \"gnupipe set output " + file + "\" -wimpslot 32k -quit"); 
  866.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  867.  
  868.  
  869.     // Reset to original term type, and replot
  870.     system ("taskwindow \"gnupipe set term  " + p.[N].term + "\" -wimpslot 32k -quit");
  871.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  872.  
  873.     if (flag1 == 1) {
  874.     mode = N;
  875.     }
  876. };
  877.  
  878.  
  879.  
  880. //
  881. // User interface to save a plot ot splot as LaTeX hardcopy
  882. //
  883.  
  884. latexplot = function ( file, mode, N )
  885. {
  886.     local ( flag1 );
  887.     flag1 = 0;
  888.     if (!exist (N) && exist (mode)) {
  889.     if (class (mode) == "num") {
  890.         N = mode;
  891.         flag1 = 1;
  892.     }
  893.     }
  894.  
  895.     if (!exist (N)) { N = 0; }
  896.     if (!exist (p.[N])) { error ("No existing plot to make hardcopy from"); }
  897.  
  898.     // Make hardcopy file
  899.     if (!exist (mode)) { mode="default"; }
  900.     if (class (mode) == "num") { mode="default"; }
  901.     system ("taskwindow \"gnupipe set term latex " + mode + "\" -wimpslot 32k -quit");
  902.     system ("taskwindow \"gnupipe set output " + file + "\" -wimpslot 32k -quit"); 
  903.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  904.  
  905.  
  906.     // Reset to original term type, and replot
  907.     system ("taskwindow \"gnupipe set term  " + p.[N].term + "\" -wimpslot 32k -quit");
  908.     system ("taskwindow \"gnupipe replot\" -wimpslot 32k -quit" );
  909.  
  910.     if (flag1 == 1) {
  911.     mode = N;
  912.     }
  913. };
  914.  
  915.  
  916. //
  917. // User interface to print a plot ot splot
  918. //
  919.  
  920. printplot = function ( printername, N )
  921. {
  922.     local(fn, flag1);
  923.     
  924.     flag1 = 0;
  925.     if (exist (printername) && !exist(N)) {
  926.     if (class (printername) == "num") {
  927.         N = printername;
  928.         clear(printername);
  929.         flag1 = 1;
  930.     }
  931.     }
  932.     
  933.     if (!exist (N)) { N = 0; }
  934.     if (!exist (p.[N])) { pobj_Create (N); }
  935.     
  936.     // Create tmp-file-name
  937.     fn = "rtmpf";
  938.  
  939.     postplot (fn, "default", N);
  940.         // Delay (RLaB is a bit to fast)
  941.     for(i in 1:1000) {
  942.     WaitAMoment=1;
  943.     clear(WaitAMoment);
  944.     }
  945.     if (exist (printername)) {
  946.     system ("lp -d" + printername + " " + fn);
  947.     else
  948.     system ("lp " + fn);
  949.     }
  950.     // Delay (RLaB is a bit to fast)
  951.     for(i in 1:1000) {
  952.     WaitAMoment=1;
  953.     clear(WaitAMoment);
  954.     }
  955.     system ("rm -f " + fn);
  956.     
  957.     if (flag1 == 1) {
  958.     printername = N;
  959.     }
  960. };
  961.  
  962.  
  963. //
  964. // User interface to save plots as GNUPLOT-datafiles
  965. //
  966.  
  967. psave = function ( file, data )
  968. {
  969.     local (ans, i, nplot, flag1);
  970.  
  971.     flag1 = 0;
  972.     // Check file-name
  973.     if (class (file) != "string") {
  974.     error ("Invalid string for file_name");
  975.     }
  976.  
  977.     // Determine how many lines to save
  978.     nplot = max ([1, data.nc - 1]);
  979.  
  980.     if (nplot > data.nr) {
  981.     printf (" Save %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  982.     ans = getline ("stdin");
  983.     if (ans.[1] != "y" && ans.[1] != "t") {
  984.         return 0;
  985.     }
  986.     if (ans.[1] == "t") {
  987.         data = data';
  988.         nplot = max ([1, data.nc - 1]);
  989.         flag1 = 1;
  990.     }
  991.     }
  992.  
  993.     // Generate two column matrices for saving
  994.     for (i in 1:nplot) {
  995.  
  996.     // Write data to file
  997.     if (nplot == 1) {
  998.         pobj_WriteData (real (data), file);
  999.         else
  1000.         pobj_WriteData (real (data[;1,i+1]), file);
  1001.     }
  1002.     }
  1003.  
  1004.     // Check flag1
  1005.     if (flag1 == 1) {
  1006.     data = data';
  1007.     }
  1008. };
  1009.  
  1010.  
  1011.  
  1012. //
  1013. // User interface to save splots as GNUPLOT-datafiles
  1014. //
  1015.  
  1016. pssave = function ( file, datax, datay, datazz)
  1017. {
  1018.     local (ans, i, nsplot, m, n, flag2, flagx, flagy);
  1019.  
  1020.     // Reset flags
  1021.     flag2=0;
  1022.     flagx=0;
  1023.     flagy=0;
  1024.  
  1025.     // Determine how many plots to draw
  1026.     if (!exist (datazz)) { 
  1027.     datazz=datax;
  1028.     datax=1:datazz.nr;
  1029.     datax=datax';
  1030.     datay=1:datazz.nc;
  1031.     datay=datay';
  1032.     flag2=flag2+1;
  1033.     }
  1034.  
  1035.     if (datax.nc != 1 ) {
  1036.     if (datax.nr != 1 ) {
  1037.         error ("Invalid data for x-axis (not a vector)");
  1038.         else
  1039.         datax = datax';
  1040.         flagx=flagx+1;
  1041.     }
  1042.     }
  1043.     if (datay.nc != 1 ) {
  1044.     if (datay.nr != 1 ) {
  1045.         error ("Invalid data for y-axis (not a vector)");
  1046.         else
  1047.         datay = datay';
  1048.         flagy=flagy+1;
  1049.     }
  1050.     }
  1051.  
  1052.     // Create file-name
  1053.     if (!exist (file)) { error ("Invalid string for file_name"); }
  1054.     if (class (file) != "string") { error ("Invalid string for file_name"); }
  1055.  
  1056.     nsplot=(datazz.nr/datazz.nc)/(datax.nr/datay.nr);
  1057.  
  1058.     // Generate three column matrices for splot program
  1059.     // Write data to new data-file
  1060.     for (i in 1:nsplot) {
  1061.     newdata=[];
  1062.     for (m in 1:datax.nr){
  1063.         rownumber=0;
  1064.         for (n in 1:datay.nr){
  1065.         rownumber=rownumber+1;
  1066.         // x-value
  1067.         newdata[rownumber;1]=datax[m];
  1068.         // y-value
  1069.         newdata[rownumber;2]=datay[n];
  1070.         // z-value
  1071.         newdata[rownumber;3]=datazz[m;n+(i-1)*datax.nr];
  1072.         }
  1073.         write (file,real (newdata[;1,2,3]));
  1074.         write (file,"");
  1075.     }
  1076.     close (file);
  1077.     }
  1078.     
  1079.     if (flag2 == 1) {
  1080.     datax=datazz;
  1081.     }
  1082.     if (flagx == 1) { datax=datax'; }
  1083.     if (flagy == 1) { datay=datay'; }
  1084.  
  1085. };
  1086.  
  1087.  
  1088.  
  1089. //
  1090. // Make multiplots
  1091. //
  1092.  
  1093. multiplot = function ( row, col, N )
  1094. {
  1095.     local (i, j, k)
  1096.     global( _MultiPlotParameter, _MultiOrginParameter );
  1097.  
  1098.     if (!exist (N)) { N = 0; }
  1099.     if (!exist (p.[N])) { pobj_Create (N); }
  1100.     _MultiPlotParameter=[row,col,1,N];
  1101.     _MultiOrginParameter=[];
  1102.     printf (" Make %i plots!\n",_MultiPlotParameter[1]*_MultiPlotParameter[2]);    
  1103.     k=1;
  1104.     for (i in 1:row) {
  1105.     for (j in 1:col) {
  1106.         _MultiOrginParameter[k;1]=(j-1)/col;
  1107.         _MultiOrginParameter[k;2]=(row-i)/row;
  1108.         k=k+1;
  1109.     }
  1110.     }
  1111. };
  1112.  
  1113.  
  1114.  
  1115. //
  1116. // Make plot with two y-axes
  1117. //
  1118.  
  1119. plotyy = function ( N )
  1120. {
  1121.     global( _PlotYyParameter );
  1122.  
  1123.     if (!exist (N)) { N = 0; }
  1124.     if (!exist (p.[N])) { pobj_Create (N); }
  1125.     printf (" Make 2 plots!\n The first on left y-axis, the second on the right!\n");
  1126.     _PlotYyParameter=1;
  1127. };
  1128.  
  1129.  
  1130.  
  1131. //
  1132. // User interface to close a GNUPLOT-window
  1133. //
  1134.  
  1135. pclose = function ( N )
  1136. {
  1137.     local (i)
  1138.     if (!exist (N)) { N = 0; }
  1139.     if (N == "all") {
  1140.     for (i in 0:99) {
  1141.         if (exist (p.[i])) {
  1142.         close (p.[i].rmf);
  1143.         close (p.[i].prog);
  1144.         pobj_Destroy (i);
  1145.         }
  1146.     }
  1147.     else
  1148.     if (!exist (p.[N])) { return -1; }
  1149.     close (p.[N].rmf);
  1150.     close (p.[N].prog);
  1151.     pobj_Destroy (N);
  1152.     }
  1153.     return N;
  1154. };
  1155.  
  1156.  
  1157.  
  1158. //
  1159. // Set the terminal type for the I-th GNUPLOT process
  1160. //
  1161.  
  1162. setterm = function ( TERM, N )
  1163. {
  1164.     if (!exist (N)) { N = 0; }
  1165.     if (!exist (p.[N])) { pobj_Create (N); }
  1166.     p.[N].term = TERM;
  1167.  
  1168.     // Now send the "set term" command to GNUPLOT
  1169.     system ("taskwindow \"gnupipe set term  " + TERM + "\" -wimpslot 32k -quit");
  1170. };
  1171.  
  1172.  
  1173.  
  1174. //
  1175. // Print out the plot list
  1176. //
  1177.  
  1178. showplot = function ( N )
  1179. {
  1180.     if (!exist (N)) { N = 0; }
  1181.     if (!exist (p.[N])) {
  1182.     pobj_Create (N);
  1183.     }
  1184.  
  1185.     printf ("\tPlot List %i\n", N);
  1186.     printf ("\t\tTerm:\t\t\t%s\n", p.[N].term);
  1187.     printf ("\t\tOutput:\t\t\t%s\n", p.[N].output);
  1188.     printf ("\t\tTmp Files:\t\t%s\n", p.[N].files);
  1189.     //    printf ("\t\tHardCopy:\t\t%s\n", p.[N].hrd);
  1190.     //    printf ("\t\tHardCopy Files:\t\t%s\n", p.[N].hrdf);
  1191. };
  1192.  
  1193. showpwin = function ()
  1194. {
  1195.     local ( i )
  1196.     for ( i in 0:99) {
  1197.     if (exist (p.[i])) {
  1198.         printf ("\tPlot window number %i exists!\n", i);
  1199.     }
  1200.     }
  1201. };
  1202.  
  1203. //
  1204. // End multiplot mode
  1205. //
  1206.  
  1207. nomultiplot = function(N)
  1208. {
  1209.     global( _MultiPlotParameter, _MultiOrginParameter, _PlotYyParameter );
  1210.  
  1211.     if (!exist (N)) { N = 0; }
  1212.     if (!exist (p.[N])) { pobj_Create (N); }
  1213.     system ("taskwindow \"gnupipe set size 1,1\" -wimpslot 32k -quit");
  1214.     system ("taskwindow \"gnupipe set orgin 0,0\" -wimpslot 32k -quit");
  1215.     system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");
  1216.     if (exist (_MultiPlotParameter)) {clear(_MultiPlotParameter);}
  1217.     if (exist (_MultiOrginParameter)) {clear(_MultiOrginParameter);}
  1218.     if (exist (_PlotYyParameter)) {clear(_PlotYyParameter);}
  1219. };
  1220.  
  1221.  
  1222.  
  1223. //
  1224. // End plotyy mode
  1225. //
  1226.  
  1227. noplotyy = function(N)
  1228. {
  1229.     global( _PlotYyParameter );
  1230.  
  1231.     if (!exist (N)) { N = 0; }
  1232.     if (!exist (p.[N])) { pobj_Create (N); }
  1233.  
  1234.     system ("taskwindow \"gnupipe set nomultiplot\" -wimpslot 32k -quit");    
  1235.     if (exist (_PlotYyParameter)) {clear(_PlotYyParameter);}
  1236. };
  1237.  
  1238.  
  1239.  
  1240. //
  1241. // Here comes a bunch of functions that really is not nessecary.
  1242. // They could be done with string("set key") etc, but this is more convinient.
  1243. //
  1244.  
  1245.  
  1246. xrange = function ( start, end, N )
  1247. {
  1248.     if (!exist (N)) { N = 0; }
  1249.     if (!exist (p.[N])) { pobj_Create (N); }
  1250.     system ("taskwindow \"gnupipe set xrange [" + start + "," + end + "]\" -wimpslot 32k -quit");    
  1251. };
  1252.  
  1253. yrange = function ( start, end, N )
  1254. {
  1255.     if (!exist (N)) { N = 0; }
  1256.     if (!exist (p.[N])) { pobj_Create (N); }
  1257.     system ("taskwindow \"gnupipe set yrange [" + start + "," + end + "]\" -wimpslot 32k -quit");    
  1258.  
  1259. };
  1260.  
  1261. zrange = function ( start, end, N )
  1262. {
  1263.     if (!exist (N)) { N = 0; }
  1264.     if (!exist (p.[N])) { pobj_Create (N); }
  1265.     system ("taskwindow \"gnupipe set zrange [" + start + "," + end + "]\" -wimpslot 32k -quit");    
  1266. };
  1267.  
  1268. range = function ( startx, endx, starty, endy, startz, endz, N )
  1269. {
  1270.     if (exist (startz) && !exist (endz)) { N = startz; }
  1271.     if (exist (starty) && !exist (endy)) { N = starty; }
  1272.     if (!exist (N)) { N = 0; }
  1273.     if (!exist (p.[N])) { pobj_Create (N); }
  1274.     system ("taskwindow \"gnupipe set xrange [" + startx + "," + endx + "]\" -wimpslot 32k -quit");    
  1275.     if (exist(endy)) {
  1276.         system ("taskwindow \"gnupipe set yrange [" + starty + "," + endy + "]\" -wimpslot 32k -quit");    
  1277.     }
  1278.     if (exist(endz)) {
  1279.         system ("taskwindow \"gnupipe set zrange [" + startz + "," + endz + "]\" -wimpslot 32k -quit");    
  1280.     }
  1281. };
  1282.  
  1283. xtics = function ( start, end, incr, N )
  1284. {
  1285.     local ( string, i )
  1286.     if (!exist (start)) { start = 0; }
  1287.     if (!exist (incr)) {
  1288.     if (length(start) > 1) {
  1289.         if (!exist (end)) { end = 0; }
  1290.         if (!exist (p.[end])) { pobj_Create (end); }
  1291.         string = "set xtics (" + num2str(start[1])[1];
  1292.         for (i in 2:length(start)) {
  1293.         string = string + "," + num2str(start[i])[1];
  1294.         }
  1295.         string = string + ")\n";
  1296.             system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");    
  1297.         else
  1298.         if (!exist (p.[start])) { pobj_Create (start); }
  1299.             system ("taskwindow \"gnupipe set xtics\" -wimpslot 32k -quit");    
  1300.     }
  1301.     else
  1302.     if (!exist (N)) { N = 0; }
  1303.     if (!exist (p.[N])) { pobj_Create (N); }
  1304.         system ("taskwindow \"gnupipe set xtics " + start + "," + incr + "," + end + "\" -wimpslot 32k -quit");    
  1305.     }
  1306. };
  1307.  
  1308. noxtics = function ( N )
  1309. {
  1310.     if (!exist (N)) { N = 0; }
  1311.     if (!exist (p.[N])) { pobj_Create (N); }
  1312.     system ("taskwindow \"gnupipe set noxtics\" -wimpslot 32k -quit");  
  1313. };
  1314.  
  1315. ytics = function ( start, end, incr, N )
  1316. {
  1317.     local ( string, i )
  1318.     if (!exist (start)) { start = 0; }
  1319.     if (!exist (incr)) {
  1320.     if (length(start) > 1) {
  1321.         if (!exist (end)) { end = 0; }
  1322.         if (!exist (p.[end])) { pobj_Create (end); }
  1323.         string = "set ytics (" + num2str(start[1])[1];
  1324.         for (i in 2:length(start)) {
  1325.         string = string + "," + num2str(start[i])[1];
  1326.         }
  1327.         string = string + ")\n";
  1328.             system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");    
  1329.         else
  1330.         if (!exist (p.[start])) { pobj_Create (start); }
  1331.         system ("taskwindow \"gnupipe set xtics\" -wimpslot 32k -quit");
  1332.     }
  1333.     else
  1334.     if (!exist (N)) { N = 0; }
  1335.     if (!exist (p.[N])) { pobj_Create (N); }
  1336.         system ("taskwindow \"gnupipe set ytics " + start + "," + incr + "," + end + "\" -wimpslot 32k -quit");    
  1337.     }
  1338. };
  1339.  
  1340. noytics = function ( N )
  1341. {
  1342.     if (!exist (N)) { N = 0; }
  1343.     if (!exist (p.[N])) { pobj_Create (N); }
  1344.     system ("taskwindow \"gnupipe set noytics\" -wimpslot 32k -quit");  
  1345. };
  1346.  
  1347. ztics = function ( start, end, incr, N )
  1348. {
  1349.     local ( string, i )
  1350.     if (!exist (start)) { start = 0; }
  1351.     if (!exist (incr)) {
  1352.     if (length(start) > 1) {
  1353.         if (!exist (end)) { end = 0; }
  1354.         if (!exist (p.[end])) { pobj_Create (end); }
  1355.         string = "set ztics (" + num2str(start[1])[1];
  1356.         for (i in 2:length(start)) {
  1357.         string = string + "," + num2str(start[i])[1];
  1358.         }
  1359.         string = string + ")\n";
  1360.             system ("taskwindow \"gnupipe " + string + "\" -wimpslot 32k -quit");    
  1361.         else
  1362.         if (!exist (p.[start])) { pobj_Create (start); }
  1363.         system ("taskwindow \"gnupipe set ztics\" -wimpslot 32k -quit");
  1364.     }
  1365.     else
  1366.     if (!exist (N)) { N = 0; }
  1367.     if (!exist (p.[N])) { pobj_Create (N); }
  1368.         system ("taskwindow \"gnupipe set ytics " + start + "," + incr + "," + end + "\" -wimpslot 32k -quit");    
  1369.     }
  1370. };
  1371.  
  1372. noztics = function ( N )
  1373. {
  1374.     if (!exist (N)) { N = 0; }
  1375.     if (!exist (p.[N])) { pobj_Create (N); }
  1376.     system ("taskwindow \"gnupipe set noztics\" -wimpslot 32k -quit");  
  1377. };
  1378.  
  1379. loglog = function ( N )
  1380. {
  1381.     if (!exist (N)) { N = 0; }
  1382.     if (!exist (p.[N])) { pobj_Create (N); }
  1383.     system ("taskwindow \"gnupipe set nologscale\" -wimpslot 32k -quit");  
  1384.     system ("taskwindow \"gnupipe set logscale xy\" -wimpslot 32k -quit");  
  1385. };
  1386.  
  1387. semilogx = function ( N )
  1388. {
  1389.     if (!exist (N)) { N = 0; }
  1390.     if (!exist (p.[N])) { pobj_Create (N); }
  1391.     system ("taskwindow \"gnupipe set logscale x\" -wimpslot 32k -quit");  
  1392. };
  1393.  
  1394. semilogy = function ( N )
  1395. {
  1396.     if (!exist (N)) { N = 0; }
  1397.     if (!exist (p.[N])) { pobj_Create (N); }
  1398.     system ("taskwindow \"gnupipe set logscale y\" -wimpslot 32k -quit");  
  1399. };
  1400.  
  1401. nolog = function ( N )
  1402. {
  1403.     if (!exist (N)) { N = 0; }
  1404.     if (!exist (p.[N])) { pobj_Create (N); }
  1405.     system ("taskwindow \"gnupipe set nologscale\" -wimpslot 32k -quit");  
  1406. };
  1407.  
  1408. autoscale = function ( axis, N )
  1409. {
  1410.     local( flag )
  1411.     flag = 0;
  1412.     if (!exist (axis) && !exist (N)) {
  1413.     N = 0;
  1414.     axis = "xy";
  1415.     }
  1416.     if (exist (axis) && !exist (N)) {
  1417.     if (class (axis) == "num") {
  1418.         N = axis;
  1419.         axis = "xy";
  1420.         flag = 1;
  1421.     }
  1422.     }
  1423.     if (!exist (p.[N])) { pobj_Create (N); }
  1424.     if (class(axis) != "string") {
  1425.     error ("Must be of class string");
  1426.     }
  1427.     system ("taskwindow \"gnupipe set autoscale " + axis + "\" -wimpslot 32k -quit");  
  1428.     if (flag == 1) { axis = N; }
  1429. };
  1430.  
  1431. xlabel = function ( string, N )
  1432. {
  1433.     if (!exist (N)) { N = 0; }
  1434.     if (!exist (p.[N])) { pobj_Create (N); }
  1435.     system ("taskwindow \"gnupipe set xlabel '" + string + "'\" -wimpslot 32k -quit");  
  1436. };
  1437.  
  1438. ylabel = function ( string, N )
  1439. {
  1440.     if (!exist (N)) { N = 0; }
  1441.     if (!exist (p.[N])) { pobj_Create (N); }
  1442.     system ("taskwindow \"gnupipe set ylabel '" + string + "'\" -wimpslot 32k -quit");  
  1443. };
  1444.  
  1445. zlabel = function ( string, N )
  1446. {
  1447.     if (!exist (N)) { N = 0; }
  1448.     if (!exist (p.[N])) { pobj_Create (N); }
  1449.     system ("taskwindow \"gnupipe set zlabel '" + string + "'\" -wimpslot 32k -quit");  
  1450. };
  1451.  
  1452. title = function ( string, N )
  1453. {
  1454.     if (!exist (N)) { N = 0; }
  1455.     if (!exist (p.[N])) { pobj_Create (N); }
  1456.     system ("taskwindow \"gnupipe set title '" + string + "'\" -wimpslot 32k -quit");  
  1457. };
  1458.  
  1459. notitle = function ( N )
  1460. {
  1461.     if (!exist (N)) { N = 0; }
  1462.     if (!exist (p.[N])) { pobj_Create (N); }
  1463.     system ("taskwindow \"gnupipe set notitle\" -wimpslot 32k -quit");  
  1464. };
  1465.  
  1466. linestyle = function ( string, N )
  1467. {
  1468.     if (!exist (N)) { N = 0; }
  1469.     if (!exist (p.[N])) { pobj_Create (N); }
  1470.     system ("taskwindow \"gnupipe set data style " + string + "\" -wimpslot 32k -quit");  
  1471. };
  1472.  
  1473. pformat = function ( string1, string2, N )
  1474. {
  1475.     local( flag1);
  1476.     flag1 = 0;
  1477.     if (!exist(string2)) {
  1478.     string2 = "xy";
  1479.     }
  1480.     if (exist (string2) && !exist (N)) {
  1481.     if (class (string2) == "num") {
  1482.         N = string2;
  1483.         string2 = "xy";
  1484.         flag1 = 1;
  1485.     }
  1486.     }
  1487.     if (!exist (N)) { N = 0; }
  1488.     if (!exist (p.[N])) { pobj_Create (N); }
  1489.     system ("taskwindow \"gnupipe set format " + string2 + "'" + string1 + "'" + "\" -wimpslot 32k -quit");  
  1490.     if (flag1 == 1) {
  1491.     string1 = string2;
  1492.     string2 = N;
  1493.     }
  1494. };
  1495.  
  1496.  
  1497. key = function ( x, y, z, N )
  1498. {
  1499.     local ( flag1 )
  1500.     flag1 = 0;
  1501.     if (exist(x) && !exist(y)) {
  1502.     N = x;
  1503.     flag1 = 1;
  1504.     }
  1505.     if (!exist (z)) { z = 0; }
  1506.     if (!exist (N)) { N = 0; }
  1507.     if (!exist (p.[N])) { pobj_Create (N); }
  1508.     if (exist(y)) {
  1509.         system ("taskwindow \"gnupipe set key " + x + "," + y + "," + z + "\" -wimpslot 32k -quit");  
  1510.     else
  1511.         system ("taskwindow \"gnupipe set key \" -wimpslot 32k -quit");  
  1512.     }
  1513.     if (flag1 == 1) {
  1514.     x = N;
  1515.     }
  1516. };
  1517.  
  1518. nokey = function ( N )
  1519. {
  1520.     if (!exist (N)) { N = 0; }
  1521.     if (!exist (p.[N])) { pobj_Create (N); }
  1522.     system ("taskwindow \"gnupipe set nokey\" -wimpslot 32k -quit");  
  1523. };
  1524.  
  1525. grid = function ( N )
  1526. {
  1527.     if (!exist (N)) { N = 0; }
  1528.     if (!exist (p.[N])) { pobj_Create (N); }
  1529.     system ("taskwindow \"gnupipe set grid\" -wimpslot 32k -quit");  
  1530. };
  1531.  
  1532. nogrid = function ( N )
  1533. {
  1534.     if (!exist (N)) { N = 0; }
  1535.     if (!exist (p.[N])) { pobj_Create (N); }
  1536.     system ("taskwindow \"gnupipe set nogrid\" -wimpslot 32k -quit");  
  1537. };
  1538.  
  1539. axis = function ( N )
  1540. {
  1541.     if (!exist (N)) { N = 0; }
  1542.     if (!exist (p.[N])) { pobj_Create (N); }
  1543.     system ("taskwindow \"gnupipe set xzeroaxis\" -wimpslot 32k -quit");  
  1544.     system ("taskwindow \"gnupipe set yzeroaxis\" -wimpslot 32k -quit");  
  1545. };
  1546.  
  1547. noaxis = function ( N )
  1548. {
  1549.     if (!exist (N)) { N = 0; }
  1550.     if (!exist (p.[N])) { pobj_Create (N); }
  1551.     system ("taskwindow \"gnupipe set noxzeroaxis\" -wimpslot 32k -quit");  
  1552.     system ("taskwindow \"gnupipe set noyzeroaxis\" -wimpslot 32k -quit");  
  1553. };
  1554.  
  1555. label = function ( label, x, y, z, labelnr, N )
  1556. {
  1557.     if (!exist (N)) { N = 0; }
  1558.     if (!exist (p.[N])) { pobj_Create (N); }
  1559.     if (class(label) != "string") {
  1560.     error ("The label must be a string!")
  1561.     }
  1562.     if (exist (labelnr)) {
  1563.     system ("taskwindow \"gnupipe set label " + label + "'" + labelnr + "' at " + x + y + z + "\" -wimpslot 32k -quit");
  1564.     else
  1565.     system ("taskwindow \"gnupipe set label '" + label + "' at " + x + y + z + "\" -wimpslot 32k -quit");
  1566.     }
  1567. };
  1568.  
  1569. nolabel = function ( labelnr, N )
  1570. {
  1571.     if (!exist (N)) { N = 0; }
  1572.     if (!exist (p.[N])) { pobj_Create (N); }
  1573.     if (exist (labelnr)) {
  1574.     system ("taskwindow \"gnupipe set nolabel " + labelnr + "\" -wimpslot 32k -quit");
  1575.     else
  1576.     system ("taskwindow \"gnupipe set nolabel\" -wimpslot 32k -quit");
  1577.     }
  1578. };
  1579.  
  1580. time = function ( N )
  1581. {
  1582.     if (!exist (N)) { N = 0; }
  1583.     if (!exist (p.[N])) { pobj_Create (N); }
  1584.     system ("taskwindow \"gnupipe set time\" -wimpslot 32k -quit");
  1585. };
  1586.  
  1587. notime = function ( N )
  1588. {
  1589.     if (!exist (N)) { N = 0; }
  1590.     if (!exist (p.[N])) { pobj_Create (N); }
  1591.     system ("taskwindow \"gnupipe set notime\" -wimpslot 32k -quit");
  1592. };
  1593.  
  1594.  
  1595. //====================
  1596. // Static Functions    =
  1597. //====================
  1598.  
  1599. plotl = function ( data, N, titles )
  1600. {
  1601.     local (I, i);
  1602.     I = 1;
  1603.     for (i in members (data)) {
  1604.     if (class (data.[i]) == "num") {
  1605.         // Check for plotting titles
  1606.         pobj_PlotKeyTitle (titles, I, title );
  1607.  
  1608.         plotm (data.[i], N, I, title);
  1609.         I++;
  1610.     }
  1611.     }
  1612. };
  1613.  
  1614.  
  1615.  
  1616. //
  1617. // Set-Up to plot a matrix. Columns 2...N against 1st column.
  1618. //
  1619.  
  1620. plotm = function ( data, N, I, titles )
  1621. {
  1622.     local (ans, fn, i, nplot, title);
  1623.     global( _RePlotParameter );
  1624.     
  1625.     flag1 = 0;
  1626.     // Determine how many lines to draw
  1627.     nplot = max ([1, data.nc - 1]);
  1628.  
  1629.     if (nplot > data.nr) {
  1630.     printf (" Plot %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  1631.     ans = getline ("stdin");
  1632.     if (ans.[1] != "y" && ans.[1] != "t") {
  1633.         return 0;
  1634.     }
  1635.     if (ans.[1] == "t") {
  1636.         data = data';
  1637.         nplot = max ([1, data.nc - 1]);
  1638.         flag1 = 1;
  1639.     }
  1640.     }
  1641.  
  1642.     // Generate two column matrices for plot program
  1643.     _RePlotParameter[N+1] = 0;
  1644.     for (i in 1:nplot) {
  1645.     // Create tmp-file-name
  1646.     fn = pobj_TmpFileName (N, i, I);
  1647.  
  1648.     // Check for plotting titles
  1649.     pobj_PlotKeyTitle (titles, i, title );
  1650.  
  1651.     // Write data to tmp-file
  1652.     // Add to plot command
  1653.     if (nplot == 1) {
  1654.         pobj_WriteData (real (data), fn);
  1655.         pobj_PlotCmd (N, fn, title);
  1656.         else
  1657.         pobj_WriteData (real (data[;1,i+1]), fn);
  1658.         pobj_PlotCmd (N, fn, title);
  1659.     }
  1660.     }
  1661.     
  1662.     // Check flag1
  1663.     if (flag1 == 1) {
  1664.     data = data';
  1665.     }
  1666.  
  1667. };
  1668.  
  1669. replotm = function ( data, N, I, titles )
  1670. {
  1671.     local ( ans, fn, i, nplot, title );
  1672.     global( _RePlotParameter );
  1673.     
  1674.     flag1 = 0;
  1675.     // Determine how many lines to draw
  1676.     nplot = max ([1, data.nc - 1]);
  1677.  
  1678.     if (nplot > data.nr) {
  1679.     printf (" Plot %i columns, are you sure [y(es)/n(o)/t(ranspose) (def. no)] ? ", data.nc);
  1680.     ans = getline ("stdin");
  1681.     if (ans.[1] != "y" && ans.[1] != "t") {
  1682.         return 0;
  1683.     }
  1684.     if (ans.[1] == "t") {
  1685.         data = data';
  1686.         nplot = max ([1, data.nc - 1]);
  1687.         flag1 = 1;
  1688.     }
  1689.     }
  1690.  
  1691.     // Generate two column matrices for plot program
  1692.     for (i in 1+_RePlotParameter[N+1]:nplot+_RePlotParameter[N+1]) {
  1693.     // Create tmp-file-name
  1694.     fn = pobj_TmpFileName (N, i, I);
  1695.  
  1696.     // Check for plotting titles
  1697.     pobj_PlotKeyTitle (titles, i, title );
  1698.  
  1699.     // Write data to tmp-file
  1700.     // Add to plot command
  1701.     if (nplot == 1) {
  1702.         pobj_WriteData (real (data), fn);
  1703.         pobj_RePlotCmd (N, fn, title);
  1704.         else
  1705.         pobj_WriteData (real (data[;1,i+1]), fn);
  1706.         pobj_RePlotCmd (N, fn, title);
  1707.     }
  1708.     }
  1709.     
  1710.     // Check flag1
  1711.     if (flag1 == 1) {
  1712.     data = data';
  1713.     }
  1714.  
  1715. };
  1716.  
  1717.  
  1718. //
  1719. // Set-Up to splot a matrix. 
  1720. //
  1721.  
  1722. splotm = function ( datax, datay, datazz, N, I, titles )
  1723. {
  1724.     local ( ans, fn, i, nsplot, m, n, title );
  1725.     global( _RePlotParameter );
  1726.     // Determine how many plots to draw
  1727.     nsplot=(datazz.nc/datazz.nr)/(datax.nr/datay.nr);
  1728.  
  1729.     // Generate three column matrices for splot program
  1730.     _RePlotParameter[N+1] = 0;
  1731.     // Write data to new data-file
  1732.     // Create tmp-file-name
  1733.     for (i in 1:nsplot) {
  1734.     fn = pobj_TmpFileName (N, i, I);
  1735.  
  1736.     // Check for plotting titles
  1737.     pobj_PlotKeyTitle (titles, I, title );
  1738.     newdata=[];
  1739.     for (m in 1:datax.nr){
  1740.         rownumber=0;
  1741.         for (n in 1:datay.nr){
  1742.         rownumber=rownumber+1;
  1743.         // x-value
  1744.         newdata[rownumber;1]=datax[m];
  1745.         // y-value
  1746.         newdata[rownumber;2]=datay[n];
  1747.         // z-value
  1748.         newdata[rownumber;3]=datazz[m;n+(i-1)*datax.nr];
  1749.         }
  1750.         write (fn,real (newdata[;1,2,3]));
  1751.         write (fn,"");
  1752.     }
  1753.     close (fn);
  1754.     // Add to splot command
  1755.     pobj_SPlotCmd (N, fn, title);
  1756.     }
  1757. };
  1758.  
  1759.  
  1760.  
  1761. //
  1762. // Set-Up to splot a matrix. 
  1763. //
  1764.  
  1765.  
  1766.  
  1767.  
  1768. //
  1769. // Form a plain string to send to GNUPLOT as 
  1770. // command
  1771. //
  1772.  
  1773. plots = function ( data, N )
  1774. {
  1775.     // Send the string to GNUPLOT
  1776.  
  1777.     p.[N].pcmd = data + "\n";
  1778. };
  1779.  
  1780.  
  1781.  
  1782. //
  1783. // Create a plot-object.
  1784. //
  1785.  
  1786. pobj_Create = function ( N )
  1787. {
  1788.     local (plist, string);
  1789.  
  1790.     // The tmp files to plot
  1791.     plist.files = "";
  1792.     // Where the plot command will go
  1793.     plist.pcmd = "";
  1794.  
  1795.     // Init string for plotting program
  1796.     plist.init = "set nogrid\nset data style lines\nset nokey\nset noxzeroaxis\nset noyzeroaxis\n";
  1797.  
  1798.     // The program that draws the plot(s)
  1799. //    sprintf (plist.prog, "|gnuplot #%i", N);
  1800. //    sprintf (plist.prog, "|gnupipe <", N);
  1801.     sprintf (plist.prog, "gnupl_cmd ", N);
  1802.  
  1803.     // To remove tmp-files
  1804.  
  1805. //    sprintf (plist.rmf, "appocmd |rm -f `cat` #%i", N);
  1806.     sprintf (plist.rmf, "wipe rtmpf%i ~C", N);
  1807. //    sprintf (plist.rmf, "", N);
  1808.     sprintf (stdout, "|rm -f `cat` #%i", N);
  1809.  
  1810.    // Keep track of terminal type, and output
  1811. //    plist.term = "X11";
  1812.      plist.term = "arcdraw col";
  1813.      plist.output = "stdout";
  1814.  
  1815.     // Copy the local list into the static plot-object collection
  1816.     p.[N] = plist;
  1817.     system ("taskwindow \"gnupipe set nogrid\" -wimpslot 32k -quit");  
  1818.     system ("taskwindow \"gnupipe set data style line\" -wimpslot 32k -quit");  
  1819.     system ("taskwindow \"gnupipe set nokey \" -wimpslot 32k -quit");  
  1820.     system ("taskwindow \"gnupipe set noxzeroaxis\" -wimpslot 32k -quit");  
  1821.     system ("taskwindow \"gnupipe set noyzeroaxis\" -wimpslot 32k -quit");  
  1822.     system ("taskwindow" + "\"gnupipe set term " + p.[N].term + "\"" + " -wimpslot 32k -quit");
  1823. };
  1824.  
  1825.  
  1826.  
  1827. //
  1828. // Reset a plot object to plot new data
  1829. //
  1830.  
  1831. pobj_Reset = function ( N )
  1832. {
  1833.  
  1834.     // Close any existing tmp-files that belong
  1835.     // to plot-object N. Reset the file-name list.
  1836.     p.[N].files = "";
  1837.     p.[N].pcmd = "";
  1838. };
  1839.  
  1840.  
  1841.  
  1842. //
  1843. // Destroy a plot-object
  1844. //
  1845.  
  1846. pobj_Destroy = function ( N )
  1847. {
  1848.     if (exist (p.[N])) {
  1849.     clear (p.[N]);    
  1850.     }
  1851. };
  1852.  
  1853.  
  1854.  
  1855. //
  1856. // Create a tmp-file name
  1857. //
  1858.  
  1859. pobj_TmpFileName = function ( N, i, j )
  1860. {
  1861.     local (tmp);
  1862.     sprintf (tmp, "rtmpf%i%i%i", N, i, j);
  1863.     p.[N].files = p.[N].files + " " + tmp;
  1864.     return tmp;
  1865. };
  1866.  
  1867.  
  1868.  
  1869. //
  1870. // Add data-file (tmp-file) to plot object list of stuff
  1871. // to be plotted.
  1872. //
  1873.  
  1874. pobj_WriteData = function ( m, file )
  1875. {
  1876.     write (file, m);
  1877.     close (file);
  1878. };
  1879.  
  1880.  
  1881.  
  1882. //
  1883. // Create the command(s) to plot all the data in the plot object.
  1884. //
  1885.  
  1886. pobj_PlotCmd = function ( N, fn, title )
  1887. {
  1888.     local (tmp);
  1889.  
  1890.     if(p.[N].pcmd == "") {
  1891.     sprintf(tmp, "plot '%s' title '%s'", fn, title);
  1892.     else
  1893.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1894.     }
  1895.  
  1896.     p.[N].pcmd = p.[N].pcmd + tmp;
  1897. };
  1898.  
  1899.  
  1900.  
  1901. //
  1902. // Create the command(s) to replot all the data in the plot object.
  1903. //
  1904.  
  1905. pobj_RePlotCmd = function ( N, fn, title )
  1906. {
  1907.     local (tmp);
  1908.  
  1909.     if(p.[N].pcmd == "") {
  1910.     sprintf(tmp, "replot '%s' title '%s'", fn, title);
  1911.     else
  1912.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1913.     }
  1914.  
  1915.     p.[N].pcmd = p.[N].pcmd + tmp;
  1916. };
  1917.  
  1918.  
  1919. //
  1920. // Create the command(s) to splot all the data in the splot object.
  1921. //
  1922.  
  1923. pobj_SPlotCmd = function ( N, fn, title )
  1924. {
  1925.     local (tmp);
  1926.  
  1927.     if(p.[N].pcmd == "") {
  1928.     sprintf(tmp, "splot '%s' title '%s'", fn, title);
  1929.     else
  1930.     sprintf(tmp,        ", '%s' title '%s'", fn, title);
  1931.     }
  1932.  
  1933.     p.[N].pcmd = p.[N].pcmd + tmp;
  1934. };
  1935.  
  1936.  
  1937.  
  1938. //
  1939. // Check for plotting titles
  1940. //
  1941.  
  1942. pobj_PlotKeyTitle = function (titles, i, title )
  1943. {
  1944.     if (!exist (titles)) {
  1945.     sprintf (title, "%.4g", i+1);
  1946.     title = "C-" + title;
  1947.     else
  1948.     if (i > length(titles)) {
  1949.         sprintf (title, "%.4g", i+1);
  1950.         title = "C-" + title;
  1951.         else
  1952.         title = titles[i];
  1953.     }
  1954.     }
  1955. };
  1956.  
  1957.  
  1958.  
  1959. //
  1960. // Force the plot program to create the plot
  1961. //
  1962.  
  1963. pobj_Plot = function ( N )
  1964. {
  1965.     //    fprintf ("stdout", "%s\n", p.[N].pcmd);
  1966.     system ("taskwindow" + "\"gnupipe " + p.[N].pcmd + "\" -wimpslot 32k -quit");
  1967.     
  1968. };
  1969.  
  1970.  
  1971.  
  1972. //
  1973. // Setup so the tmp-files can be removed
  1974. //
  1975.  
  1976. pobj_SetRm = function ( N )
  1977. {
  1978.     fprintf(p.[N].rmf, "%s", p.[N].files);
  1979.     system(p.[N].rmf);
  1980. };
  1981.  
  1982.  
  1983.  
  1984. //
  1985. // Remove the tmp-files
  1986. //
  1987.  
  1988. pobj_Rm = function ( N )
  1989. {
  1990.     if (length (p.[N].files) != 0) {
  1991.     close (p.[N].rmf);
  1992.     }
  1993. };
  1994.  
  1995.  
  1996.  
  1997. //
  1998. // Provide access to the plot-list
  1999. //
  2000.  
  2001. _pobj_list = function ( N )
  2002. {
  2003.     if (!exist (N)) { N = 0; }
  2004.     return p.[N];
  2005. };
  2006.  
  2007.